﻿package com.wandian.view.components.ui.chip
{    
	import com.wandian.data.GameData;
	
	import flash.display.Sprite;

	/**   
	 * 根据下注金额显示金钱
	 * @author long
	 * @QQ 108232706
	 * @version 1.0   
	 */
    public class CountChip extends Sprite
    {
        private var recordChip:int;
        private var recordX:Number;

        public function CountChip() : void
        {
            this.recordChip = 0;
            this.recordX = 0;
            return;
        }

        private function addChip(chipNum:int) : void
        {
            var mcChipNum:* = this.showChipNum(chipNum);
            this.addChild(mcChipNum);
            mcChipNum.x = this.recordX;
            mcChipNum.y = (-this.recordChip) * 3;
            if (this.recordChip == 4)
            {
                this.recordChip = 0;
                this.recordX = this.recordX + mcChipNum.width;
            }
            return;
        }

        public function removeChip() : void
        {
            var mcChipNum:* = undefined;
            while (this.numChildren > 0)
            {
                
                mcChipNum = this.removeChildAt((this.numChildren - 1));
                mcChipNum = null;
            }
            this.recordChip = 0;
            this.recordX = 0;
            return;
        }

        public function recursionHandler(callChipNum:int) : void
        {
            if (callChipNum <= 0)
            {
                return;
            }
            var chipNum:int = this.countChipNum(callChipNum);
            this.addChip(chipNum);
			this.recordChip++;
            this.recursionHandler(callChipNum - chipNum);
            return;
        }

        private function countChipNum(chipNum:int) : int
        {
            if (chipNum >= 5000000000)
            {
                return 5000000000;
            }
            if (chipNum >= 2000000000)
            {
                return 2000000000;
            }
            if (chipNum >= 1000000000)
            {
                return 1000000000;
            }
            if (chipNum >= 500000000)
            {
                return 500000000;
            }
            if (chipNum >= 200000000)
            {
                return 200000000;
            }
            if (chipNum >= 100000000)
            {
                return 100000000;
            }
            if (chipNum >= 50000000)
            {
                return 50000000;
            }
            if (chipNum >= 20000000)
            {
                return 20000000;
            }
            if (chipNum >= 10000000)
            {
                return 10000000;
            }
            if (chipNum >= 5000000)
            {
                return 5000000;
            }
            if (chipNum >= 2000000)
            {
                return 2000000;
            }
            if (chipNum >= 1000000)
            {
                return 1000000;
            }
            if (chipNum >= 500000)
            {
                return 500000;
            }
            if (chipNum >= 200000)
            {
                return 200000;
            }
            if (chipNum >= 100000)
            {
                return 100000;
            }
            if (chipNum >= 50000)
            {
                return 50000;
            }
            if (chipNum >= 20000)
            {
                return 20000;
            }
            if (chipNum >= 10000)
            {
                return 10000;
            }
            if (chipNum >= 5000)
            {
                return 5000;
            }
            if (chipNum >= 2000)
            {
                return 2000;
            }
            if (chipNum >= 1000)
            {
                return 1000;
            }
            if (chipNum >= 500)
            {
                return 500;
            }
            if (chipNum >= 200)
            {
                return 200;
            }
            if (chipNum >= 100)
            {
                return 100;
            }
            if (chipNum >= 50)
            {
                return 50;
            }
            if (chipNum >= 20)
            {
                return 20;
            }
            if (chipNum >= 10)
            {
                return 10;
            }
            if (chipNum >= 5)
            {
                return 5;
            }
            if (chipNum >= 2)
            {
                return 2;
            }
            if (chipNum >= 1)
            {
                return 1;
            }
            return 0;
        }

        private function showChipNum(chipNum:int) : Sprite
        {
            switch(chipNum)
            {
                case 1:
                {
                    return GameData.getSprite("Chips1");
                }
                case 2:
                {
                    return GameData.getSprite("Chips2");
                }
                case 5:
                {
                    return GameData.getSprite("Chips5");
                }
                case 10:
                {
                    return GameData.getSprite("Chips10");
                }
                case 20:
                {
                    return GameData.getSprite("Chips20");
                }
                case 50:
                {
                    return GameData.getSprite("Chips50");
                }
                case 100:
                {
                    return GameData.getSprite("Chips100");
                }
                case 200:
                {
                    return GameData.getSprite("Chips200");
                }
                case 500:
                {
                    return GameData.getSprite("Chips500");
                }
                case 1000:
                {
                    return GameData.getSprite("Chips1000");
                }
                case 2000:
                {
                    return GameData.getSprite("Chips2000");
                }
                case 5000:
                {
                    return GameData.getSprite("Chips5000");
                }
                case 10000:
                {
                    return GameData.getSprite("Chips10000");
                }
                case 20000:
                {
                    return GameData.getSprite("Chips20000");
                }
                case 50000:
                {
                    return GameData.getSprite("Chips50000");
                }
                case 100000:
                {
                    return GameData.getSprite("Chips100000");
                }
                case 200000:
                {
                    return GameData.getSprite("Chips200000");
                }
                case 500000:
                {
                    return GameData.getSprite("Chips500000");
                }
                case 1000000:
                {
                    return GameData.getSprite("Chips1000000");
                }
                case 2000000:
                {
                    return GameData.getSprite("Chips2000000");
                }
                case 5000000:
                {
                    return GameData.getSprite("Chips5000000");
                }
                case 10000000:
                {
                    return GameData.getSprite("Chips10000000");
                }
                case 20000000:
                {
                    return GameData.getSprite("Chips20000000");
                }
                case 50000000:
                {
                    return GameData.getSprite("Chips50000000");
                }
                case 100000000:
                {
                    return GameData.getSprite("Chips100000000");
                }
                case 200000000:
                {
                    return GameData.getSprite("Chips200000000");
                }
                case 500000000:
                {
                    return GameData.getSprite("Chips500000000");
                }
                case 1000000000:
                {
                    return GameData.getSprite("Chips1000000000");
                }
                case 2000000000:
                {
                    return GameData.getSprite("Chips2000000000");
                }
                case 5000000000:
                {
                    return GameData.getSprite("Chips5000000000");
                }
                default:
                {
                    return new Sprite();
                    break;
                }
            }
        }

    }
}
